﻿using System.Linq;
using System.Linq.Expressions;
using System.Reflection;

namespace NMapper.Utils
{
    public class NameHelpers
    {
        public static string SuggestName(LambdaExpression selector)
        {
            var dbPropertyPath = selector.GetPropertyPath().Cast<PropertyInfo>();
            if (dbPropertyPath.Any())
            {
                return string.Join("_", dbPropertyPath.Select(x => x.Name));
            }
            else
                return null;
        } 

        public static string SuggestName(LambdaExpression dbSelector, LambdaExpression outputSelector)
        {
            return SuggestName(dbSelector) ?? SuggestName(outputSelector);
        } 
    }
}